package com.springcloud.sc.ucpv5.client.commondata.data;

import java.util.Arrays;

import com.springcloud.sc.ucpv5.client.commondata.datachange.DataExChange;

public class Device extends DataExChange {
    public String deviceid; // 设备ID
    public int sumnum = 2; // 子设备个数
    public SubDeviceItem[] item; // 子设备列表

    /**
     * 从probuf对象获取当前对象
     * 
     * @param builder_src
     * @return
     */
    public void dataChangeProBufDataToCommon(com.google.protobuf.Message builder_src) {
	try {
	    com.proto.uuos_sdk_pb.GbDeviceListQueryList.Device builder_dst = (com.proto.uuos_sdk_pb.GbDeviceListQueryList.Device) builder_src;

	    deviceid = builder_dst.getDeviceid();
	    sumnum = builder_dst.getSumnum();

	    item = new com.springcloud.sc.ucpv5.client.commondata.data.SubDeviceItem[builder_dst.getItemCount()];

	    System.out.println("deviceId:" + deviceid);
	    for (int i = 0; i < builder_dst.getItemCount(); i++) {
		item[i] = new com.springcloud.sc.ucpv5.client.commondata.data.SubDeviceItem();
		item[i].dataChangeProBufDataToCommon(builder_dst.getItem(i));

		System.out.println("subDevic: deviceId:" + item[i].deviceid + " civilcode:" + item[i].civilcode + " parentid:" + item[i].parentid + " name:"
			+ item[i].name);
		System.out.println(item[i].toString());
	    }
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }


    public String toString() {
	return "Device [deviceid=" + deviceid + ", sumnum=" + sumnum + ", item=" + Arrays.toString(item) + "]";
    }
    
    
}
